package com.qf.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 千锋健哥
 */
public class CustomExcepitonResolver implements HandlerExceptionResolver {

    /**
     * 处理全局异常
     */
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Object o,
                                         Exception exc) {
        /**
         * 模型和视图对象
         * model中放返回给页面的数据
         * view中指定页面的位置和名称
         */
        ModelAndView modelAndView = new ModelAndView();
        //传入页面的数据
        modelAndView.addObject("error", "我错了, 真的知道错了!!!求原谅");
        //指定页面的位置和名称
        modelAndView.setViewName("error1");

        return modelAndView;
    }

}
